﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IWMAG.Scripting.Types {
    public class ReferenceType : CodeType {
        public string[] Identifier;

        public ReferenceType(IEnumerable<string> name) {
            List<string> s = new List<string>(name);
            Identifier = s.ToArray();
        }

        public override string ToString() {
            return string.Join(".", Identifier);
        }

        public override bool Equals(object obj) {
            if (!(obj is ReferenceType)) {
                return false;
            }

            ReferenceType r = obj as ReferenceType;
            if (r.Identifier.Length != Identifier.Length) {
                return false;
            }

            for (int i = 0; i < Identifier.Length; i++ ) {
                if (r.Identifier[i] != Identifier[i]) {
                    return false;
                }
            }

            return true;
        }

        public override int GetHashCode() {
            return string.Join(".", Identifier).GetHashCode();
        }
    }
}
